package nina.yiyou.salary.input.util

import java.nio.file.Path
import java.nio.file.Paths

class InputPathResolver {

  static InputPathResolver create(Path workshopPath, Map configMap, String pathKey) {
    def path = configMap[pathKey] as String
    assert path, pathKey
    return new InputPathResolver(workshopPath, path)
  }

  InputPathResolver(Path workshopPath, String pathStr) {
    _workshopPath = workshopPath
    _pathStr = pathStr
  }

  Path resolve() {
    Path path = Paths.get(_pathStr)
    if (path.isAbsolute()) {
      return path
    }
    return _workshopPath.resolveSibling(path).normalize()
  }

  private final Path _workshopPath

  private final String _pathStr
}
